home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / winsr173.zip / JB.C < prev    next >
C/C++ Source or Header  |  1991-07-07  |  9KB  |  248 lines

  1. #include <stdlib.h>
  2. #include "fractint.h"
  3. #include "mpmath.h"
  4. #include "helpdefs.h"
  5.  
  6. extern  int fullscreen_prompt(char *hdg,int numprompts,char * far *prompts,
  7.                struct fullscreenvalues values[],int options,int fkeymask,
  8.                char far *extrainfo);
  9. void stackscreen(void);
  10. void unstackscreen(void);
  11.  
  12. extern int row, col, xdots, ydots, bitshift, fractype;
  13. extern int ixstart, ixstop, iystart, iystop, colors, helpmode;
  14. extern double param[], xxmin, xxmax, yymin, yymax;
  15. extern long delx, dely, ltempsqrx, ltempsqry, far *lx0, far *ly0;
  16. extern struct lcomplex lold, lnew, *longparm;
  17. extern llimit2;
  18. static int bbase;
  19. static long xpixel, ypixel;
  20. static long initz, djx, djy, dmx, dmy;
  21. static long jx, jy, mx, my, xoffset, yoffset;
  22. static long jxmin, jxmax, jymin, jymax, mxmin, mxmax, mymin, mymax;
  23. static long x_per_inch, y_per_inch, inch_per_xdot, inch_per_ydot;
  24. struct Perspective {
  25.    long x, y, zx, zy;
  26. };
  27.  
  28. struct Perspective LeftEye, RightEye, *Per;
  29. struct lcomplex jbc;
  30.  
  31. #define NUM_VAR 17
  32.  
  33. static double fg, fg16;
  34. static long
  35.         zdots = 128L,
  36.         shell = 30L,
  37.         origin = (long)(8.0 * (1L << 16)),
  38.    height = (long)(7.0 * (1L << 16)),
  39.         width = (long)(10.0 * (1L << 16)),
  40.    dist = (long)(24.0 * (1L << 16)),
  41.    eyes = (long)(0.0 * (1L << 16)),
  42.    depth = (long)(8.0 * (1L << 16)),
  43.    brratio = (long)(0.0 * (1L << 16));
  44.  
  45. int JulibrotSetup(void) {
  46.         int r;
  47.         int oldhelpmode;
  48.    struct fullscreenvalues d[NUM_VAR];
  49.    static char StereoFile[] = "glasses1.map";
  50.    static char GreyFile[] = "altern.map";
  51.    char *mapname;
  52.    static char *v[NUM_VAR] = {
  53.       "Julia from x",                              /* d[0] */
  54.       "Julia to x",                                /* d[1] */
  55.       "Julia from y",                              /* d[2] */
  56.       "Julia to y",                                /* d[3] */
  57.       "Mandelbrot from x",                         /* d[4] */
  58.       "Mandelbrot to x",                           /* d[5] */
  59.       "Mandelbrot from y",                         /* d[6] */
  60.       "Mandelbrot to y",                           /* d[7] */
  61.       "Number of z pixels",                        /* d[8] */
  62.       "Penetration level",                         /* d[9] */
  63.       "Location of z origin",                      /* d[10] */
  64.       "Depth of z",                                /* d[11] */
  65.       "Screen height",                             /* d[12] */
  66.       "Screen width",                              /* d[13] */
  67.       "Distance to Screen",                        /* d[14] */
  68.       "Distance between eyes (0 for Greyscale)",   /* d[15] */
  69.       "Blue:Red Ratio (0 for Greyscale)",          /* d[16] */
  70.    };
  71.  
  72.    if(colors < 255) {
  73.       static char far msg[]=
  74.           {"Sorry, but Julibrots require a 256-color video mode"};
  75.       stopmsg(0,msg);
  76.       return(0);
  77.    }
  78.  
  79.    fg = (double)(1L << bitshift);
  80.    fg16 = (double)(1L << 16);
  81.  
  82.    for (r = 0; r < NUM_VAR; ++r)
  83.       d[r].type = 'f';
  84.  
  85.         jxmax = (long)((d[0].uval.dval = xxmax) * fg);
  86.         jxmin = (long)((d[1].uval.dval = xxmin) * fg);
  87.         jymax = (long)((d[2].uval.dval = yymax) * fg);
  88.         jymin = (long)((d[3].uval.dval = yymin) * fg);
  89.         mxmax = (long)((d[4].uval.dval = param[0]) * fg);
  90.         mxmin = (long)((d[5].uval.dval = param[1]) * fg);
  91.         mymax = (long)((d[6].uval.dval = param[2]) * fg);
  92.         mymin = (long)((d[7].uval.dval = param[3]) * fg);
  93.    d[8].uval.dval = (double)zdots;
  94.    d[9].uval.dval = (double)shell;
  95.    d[10].uval.dval = (double)origin / fg16;
  96.    d[11].uval.dval = (double)depth / fg16;
  97.    d[12].uval.dval = (double)height / fg16;
  98.    d[13].uval.dval = (double)width / fg16;
  99.    d[14].uval.dval = (double)dist / fg16;
  100.    d[15].uval.dval = (double)eyes / fg16;
  101.    d[16].uval.dval = (double)brratio / fg16;
  102.  
  103.    stackscreen();
  104.    oldhelpmode = helpmode;
  105.    helpmode = HT_JULIBROT;
  106.    if((r = fullscreen_prompt("Julibrot Parameters",
  107.                               NUM_VAR, v, d, 0, 0, 0)) >= 0) {
  108.       jxmin = (long)((xxmax = d[0].uval.dval) * fg);
  109.       jxmax = (long)((xxmin = d[1].uval.dval) * fg);
  110.       xoffset = (jxmax + jxmin) / 2;       /* Calculate average */
  111.       jymin = (long)((yymax = d[2].uval.dval) * fg);
  112.       jymax = (long)((yymin = d[3].uval.dval) * fg);
  113.       yoffset = (jymax + jymin) / 2;       /* Calculate average */
  114.       mxmin = (long)((param[0] = d[4].uval.dval) * fg);
  115.       mxmax = (long)((param[1] = d[5].uval.dval) * fg);
  116.       mymin = (long)((param[2] = d[6].uval.dval) * fg);
  117.       mymax = (long)((param[3] = d[7].uval.dval) * fg);
  118.       zdots = (long)(d[8].uval.dval);
  119.       shell = (long)(d[9].uval.dval);
  120.       origin = (long)(d[10].uval.dval * fg16);
  121.       depth = (long)(d[11].uval.dval * fg16);
  122.       height = (long)(d[12].uval.dval * fg16);
  123.       width = (long)(d[13].uval.dval * fg16);
  124.       dist = (long)(d[14].uval.dval * fg16);
  125.       eyes = (long)(d[15].uval.dval * fg16);
  126.       brratio = (long)(d[16].uval.dval * fg16);
  127.       dmx = (mxmax - mxmin) / zdots;
  128.       dmy = (mymax - mymin) / zdots;
  129.       longparm = &jbc;
  130.  
  131.       x_per_inch = (long)((d[1].uval.dval - d[0].uval.dval) / d[13].uval.dval * fg);
  132.       y_per_inch = (long)((d[3].uval.dval - d[2].uval.dval) / d[12].uval.dval * fg);
  133.                 inch_per_xdot = (long)(d[13].uval.dval / xdots * fg16);
  134.                 inch_per_ydot = (long)(d[12].uval.dval / ydots * fg16);
  135.       initz = origin - (depth / 2);
  136.       LeftEye.x = -(RightEye.x = eyes / 2);
  137.       LeftEye.y = RightEye.y = 0l;
  138.       LeftEye.zx = RightEye.zx = dist;
  139.       LeftEye.zy = RightEye.zy = dist;
  140.       bbase = (int)(128.0 * d[16].uval.dval);
  141.    }
  142.  
  143.    helpmode = oldhelpmode;
  144.    unstackscreen();
  145.  
  146.    if(d[16].uval.dval == 0.0)
  147.       mapname = GreyFile;
  148.    else
  149.       mapname = StereoFile;
  150.    if (ValidateLuts(mapname) != 0)
  151.       return(0);
  152.    spindac(0,1);                 /* load it, but don't spin */
  153.  
  154.    return(r >= 0);
  155. }
  156.  
  157. int jb_per_pixel(void) {
  158.         jx = multiply(Per->x - xpixel, initz, 16);
  159.    jx = divide(jx, dist, 16) - xpixel;
  160.    jx = multiply(jx << (bitshift - 16), x_per_inch, bitshift);
  161.    jx += xoffset;
  162.         djx = divide(depth, dist, 16);
  163.         djx = multiply(djx, Per->x - xpixel, 16) << (bitshift - 16);
  164.         djx = multiply(djx, x_per_inch, bitshift) / zdots;
  165.  
  166.         jy = multiply(Per->y - ypixel, initz, 16);
  167.         jy = divide(jy, dist, 16) - ypixel;
  168.         jy = multiply(jy << (bitshift - 16), y_per_inch, bitshift);
  169.    jy += yoffset;
  170.         djy = divide(depth, dist, 16);
  171.         djy = multiply(djy, Per->y - ypixel, 16) << (bitshift - 16);
  172.         djy = multiply(djy, y_per_inch, bitshift) / zdots;
  173.  
  174.    return(1);
  175. }
  176.  
  177. static int n, zpixel, plotted, color;
  178.  
  179. int zline(long x, long y) {
  180.    xpixel = x;
  181.    ypixel = y;
  182.         mx = mxmin;
  183.         my = mymin;
  184.    if((row + col) & 1)
  185.       Per = &LeftEye;
  186.    else
  187.       Per = &RightEye;
  188.    curfractalspecific->per_pixel();
  189.    for(zpixel = 0; zpixel < zdots; zpixel++) {
  190.       lold.x = jx;
  191.       lold.y = jy;
  192.       jbc.x = mx;
  193.       jbc.y = my;
  194.       if(check_key())
  195.          return(-1);
  196.       ltempsqrx = multiply(lold.x, lold.x, bitshift);
  197.       ltempsqry = multiply(lold.y, lold.y, bitshift);
  198.       for(n = 0; n < shell; n++) {
  199.          if(curfractalspecific->orbitcalc())
  200.             break;
  201.       }
  202.       if(n == shell) {
  203.          if(brratio) {
  204.             color = (int)(128l * zpixel / zdots);
  205.             if((row + col) & 1)
  206.                (*plot)(col, row, 127 - color);
  207.             else {
  208.                                 color = (int)(multiply((long)color << 16, brratio, 16) >> 16);
  209.                (*plot)(col, row, 127 + bbase - color);
  210.             }
  211.          }
  212.          else {
  213.             color = (int)(254l * zpixel / zdots);
  214.             (*plot)(col, row, color + 1);
  215.          }
  216.          plotted = 1;
  217.          break;
  218.       }
  219.       mx += dmx;
  220.       my += dmy;
  221.       jx += djx;
  222.       jy += djy;
  223.    }
  224.    return(0);
  225. }
  226.  
  227. int Std4dFractal(void) {
  228.    long x, y;
  229.    int xdot, ydot;
  230.  
  231.    for(y = 0, ydot = (ydots >> 1) - 1; ydot >= 0; ydot--, y -= inch_per_ydot) {
  232.                 plotted = 0;
  233.                 x = -(width >> 1);
  234.                 for(xdot = 0; xdot < xdots; xdot++, x += inch_per_xdot) {
  235.          col = xdot;
  236.          row = ydot;
  237.          if(zline(x, y) < 0)
  238.             return(-1);
  239.          col = xdots - col - 1;
  240.          row = ydots - row - 1;
  241.          if(zline(-x, -y) < 0)
  242.             return(-1);
  243.       }
  244.       if(!plotted) break;
  245.    }
  246.    return(0);
  247. }
  248.